<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            box-sizing: border-box;
        }
        
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0;
            overflow: hidden;
        }
        
        ul {
            list-style: none;
            padding: 0;
            margin: 0;
            display: flex;
            justify-content: space-around;
            height: 50px;
            align-items: center;
            background-color: #fff;
        }
        
        .content {
            height: calc(100% - 50px);
            overflow: auto;
        }
    </style>
</head>

<body>
    <div id="app">
        <router-view class="content" :key="$route.fullPath"></router-view>
        <ul>
            <router-link tag="li" to="/all">全部</router-link>
            <router-link tag="li" to="/good">精华</router-link>
            <router-link tag="li" to="/share">分享</router-link>
            <router-link tag="li" to="/ask">问答</router-link>
        </ul>
    </div>
    <script src="./js/vue.js"></script>
    <script src="./js/vue-router.js"></script>
    <script src="./js/axios.js"></script>
    <script>
        const Index = {
            template: `<div>
                    <div v-for="item in list" :key="item.id">{{item.title}}</div>
                </div>`,
            data() {
                return {
                    list: []
                }
            },
            created() {
                console.log(this.$route);
                axios.get('https://cnodejs.org/api/v1/topics?tab=' + this.$route.params.aaa).then(res => {
                    // console.log(res);
                    this.list = res.data.data
                })

            }
        }

        // const Type = {
        //     template: `<div>分类</div>`
        // }

        // const Cart = {
        //     template: `<div>购物车</div>`
        // }

        // const My = {
        //     template: `<div>我的</div>`
        // }

        // const Detail = {
        //     template: `<div>详情页</div>`
        // }
        // 动态路由本身并不会重新渲染页面
        let router = new VueRouter({
            routes: [{
                path: '/:aaa',
                component: Index
            }]
        })


        new Vue({
            el: "#app",
            router
        })
    </script>
</body>

</html>